/**
 * 
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShBuidingTypeDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShBuidingTypeService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShBuidingType;
import com.smarthome.domain.bean.ShBuilding;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * @author dhc
 * @date 2016年3月8日 下午10:19:54
 * @title
 */
@Service("shBuidingTypeService")
public class ShBuidingTypeServiceImpl extends BaseServiceImpl<ShBuidingType, Long> implements ShBuidingTypeService{

	@Resource
	private ShBuidingTypeDao buidingTypeDao;	
	/* (non-Javadoc)
	 * @see com.smarthome.base.service.base.BaseServiceImpl#getDao()
	 */
	@Override
	public BaseDao<ShBuidingType, Long> getDao() {
		// TODO Auto-generated method stub
		return buidingTypeDao;
	}
	/* (non-Javadoc)
	 * @see com.smarthome.base.service.ShBuidingTypeService#getDataGrid(com.smarthome.domain.bean.ShBuidingType, com.smarthome.domain.vo.boss.PageHelper)
	 */
	@Override
	public DataGrid getDataGrid(ShBuidingType buidingType, PageHelper page) {
		DataGrid grid = new DataGrid();

		if(buidingType == null) buidingType = new ShBuidingType();
		if (!StringUtils.isBlank(page.getOrder())) {
			buidingType.setOrderFieldType(page.getOrder());
		}
		if (!StringUtils.isBlank(page.getSort())) {
			buidingType.setOrderField(page.getSort());
		}
		int count = buidingTypeDao.selectEntryListCount(buidingType);
		grid.setTotal(count + 0L);
		if(count > 0){
			int startIndex = (page.getPage() - 1) * page.getRows();
			int endIndex = page.getPage() * page.getRows();
			buidingType.setOrderField(page.getSort());
			buidingType.setOrderFieldType(page.getOrder());
			buidingType.setStartIndex(startIndex);
			buidingType.setEndIndex(endIndex);
			List<ShBuidingType> lists = buidingTypeDao.selectEntryList(buidingType);
			grid.setRows(lists);
		}
		
		return  grid;
	}

}
